﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RDotNet;
using Rclr;

namespace CreateRdnObjects
{
    // See also F:\TIME\Partners\CSIRO\R\CSIRO.TIME2R\TimeToRDataConversion.cs for reusing prior investigative work
    public class RdotnetObjFactory
    {
        public REngine Engine { get; set; }
        public SymbolicExpression CreateDataFrameWithStrings()
        {
            var aList = CreateGenericVector();
            return aList.AsDataFrame();
        }

        public GenericVector CreateGenericVector()
        {
            var a = Engine.CreateNumericVector(new[] {1.0, 3.0, 2.0, 4.0, 3.0, 5});
            var b = Engine.CreateCharacterVector(new[] {"a", "a", "a", "b", "b", "b"});
            var aList = new GenericVector(Engine, new SymbolicExpression[] {a, b});
            return aList;
        }

        public void GetREngine(RDotNetDataConverter dconv)
        {
            this.Engine = dconv.GetEngine();
        }

        public string CheckObjectType(object obj)
        {
            if (obj == null)
                return "object reference is null";
            return obj.GetType().FullName;
        }
    }
}
